package com.example.crawler.config;

import com.google.common.util.concurrent.ThreadFactoryBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.concurrent.*;

/**
 * @author pq
 * @date 2022/10/28 9:49
 * @description
 * @modified
 **/
@Configuration
public class SystemConfig {

    /**
     * 线程池
     *
     * @return
     */
    @Bean(name = "doapool")
    public ExecutorService makePool() {
        ThreadFactory tf = new ThreadFactoryBuilder().setNameFormat("doapool-pool-%d").build();
        return new ThreadPoolExecutor(Runtime.getRuntime().availableProcessors() * 2, Runtime.getRuntime().availableProcessors() * 8, 0L, TimeUnit.MILLISECONDS
                , new LinkedBlockingDeque<>(1024), tf, new ThreadPoolExecutor.CallerRunsPolicy());
    }

}
